{extend name="public/main" /}

{block name="body"}
<div class="layui-fluid">
    <form action="" method="post" class="xn_ajax layui-form">
        <input type="hidden" name="id" value="{$group_data['id']}">
        <table class="layui-table" style="margin-top: 0;">
            {foreach name="rule_data" item="v"}
            <empty name="v['_data']">
                <tr class="b-group">
                    <th>
                        <input type="checkbox" name="rule_ids[]" value="{$v['id']}" {if condition="in_array($v['id'],$group_data['rules'])"} checked="checked"{/if} lay-skin="primary" title="{$v['title']}" lay-filter="allChoose">
                    </th>
                    <td></td>
                </tr>
                <else />
                <tr class="b-group">
                    <th>
                        <input type="checkbox" name="rule_ids[]" value="{$v['id']}" {if condition="in_array($v['id'],$group_data['rules'])"} checked="checked"{/if} lay-skin="primary" title="{$v['title']}" lay-filter="allChoose">
                    </th>
                    <td class="b-child">
                        {foreach name="v['_data']" item="n"}
                        <table class="layui-table">
                            <tr class="b-group">
                                <th width="120">
                                    <input type="checkbox" name="rule_ids[]" value="{$n['id']}" {if condition="in_array($n['id'],$group_data['rules'])"} checked="checked"{/if} lay-skin="primary" title="{$n['title']}" lay-filter="allChoose">
                                </th>
                                <td class="b-child">
                                    {foreach name="n['_data']" item="e"}
                                    <table class="layui-table">
                                        <tr class="b-group">
                                            <th width="120">
                                                <input type="checkbox" name="rule_ids[]" value="{$e['id']}" {if condition="in_array($e['id'],$group_data['rules'])"} checked="checked"{/if} lay-skin="primary" title="{$e['title']}" lay-filter="allChoose">
                                            </th>
                                            <td class="b-child">
                                                {foreach name="e['_data']" item="g"}
                                                <table class="layui-table">
                                                    <tr class="b-group">
                                                        <th width="120">
                                                            <input type="checkbox" name="rule_ids[]" value="{$g['id']}" {if condition="in_array($g['id'],$group_data['rules'])"} checked="checked"{/if} lay-skin="primary" title="{$g['title']}" lay-filter="allChoose">
                                                        </th>
                                                        <td class="b-child">
                                                            {foreach name="g['_data']" item="t"}
                                                            <table class="layui-table">
                                                                <tr class="b-group">
                                                                    <th width="120">
                                                                        <input type="checkbox" name="rule_ids[]" value="{$t['id']}" {if condition="in_array($t['id'],$group_data['rules'])"} checked="checked"{/if} lay-skin="primary" title="{$t['title']}" lay-filter="allChoose">
                                                                    </th>
                                                                    <td>
                                                                        {notempty name="t['_data']"}
                                                                        {volist name="t['_data']" id="c"}
                                                                        &emsp;<input type="checkbox" name="rule_ids[]" value="{$c['id']}" {if condition="in_array($c['id'],$group_data['rules'])"} checked="checked"{/if} lay-skin="primary" title="{$c['title']}">
                                                                        {/volist}
                                                                        {/notempty}
                                                                    </td>
                                                                </tr>
                                                            </table>
                                                            {/foreach}
                                                        </td>
                                                    </tr>
                                                </table>
                                                {/foreach}
                                            </td>
                                        </tr>
                                    </table>
                                    {/foreach}
                                </td>
                            </tr>
                        </table>
                        {/foreach}
                    </td>
                </tr>
            </empty>
            {/foreach}
            <tr>
                <th></th>
                <td>
                    <input class="layui-btn" type="submit" value="提交">
                </td>
            </tr>
        </table>
    </form>
</div>
{/block}

{block name="js"}
<script>
    layui.use(['form','jquery'], function () {
        var form = layui.form;
        var $ = layui.jquery;
        //点击全选, 勾选
        form.on('checkbox(allChoose)', function (data) {
            var child = $(this).parents('.b-group').eq(0).find("input[type='checkbox']");
            child.each(function (index, item) {
                item.checked = data.elem.checked;
            });
            form.render('checkbox');
        });
    });
</script>
{/block}